package cn.com.infohold.smartcity.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.List;

import cn.com.infohold.smartcity.R;
import cn.com.infohold.smartcity.activity.Dispute.DisputeDetail_Activity;
import cn.com.infohold.smartcity.api.bean.DisputeBean;
import cn.com.infohold.smartcity.parent.ParentActivity;
import library.utils.Utils;

/**
 * Created by Monsoon on 2017/11/3.
 */
public class Dispute_Adapter extends RecyclerView.Adapter<Dispute_Adapter.mViewHolder>{

    private Context context;
    private List<DisputeBean> mList;
    private boolean isDispute;

    public Dispute_Adapter(Context context, List<DisputeBean> mList, boolean isDispute) {
        this.context = context;
        this.mList = mList;
        this.isDispute = isDispute;
    }

    @Override
    public mViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        mViewHolder viewHolder = new mViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_dispute, parent, false));
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(mViewHolder holder, int position) {

        DisputeBean bean = mList.get(position);
        holder.tv_warrantId.setText(bean.getWarrantId());
        holder.tv_landId.setText(bean.getLandId());
        holder.tv_contractnumber.setText(bean.getContractnumber());
        holder.tv_disputeTime.setText(bean.getDisputeTime());

        holder.ll_item.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context,DisputeDetail_Activity.class);
                Bundle bundle = new Bundle();
                bundle.putSerializable("dispute_detail",bean);
                bundle.putBoolean("isDispute",isDispute);
                intent.putExtra("dispute_detail",bundle);
                context.startActivity(intent);
                ((ParentActivity)context).overridePendingTransitionFade();
            }
        });
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    class mViewHolder extends RecyclerView.ViewHolder{
        LinearLayout ll_item;
        TextView tv_warrantId;
        TextView tv_landId;
        TextView tv_contractnumber;
        TextView tv_disputeTime;

        public mViewHolder(View itemView) {
            super(itemView);
            ll_item = (LinearLayout) itemView.findViewById(R.id.ll_item);
            tv_warrantId = (TextView) itemView.findViewById(R.id.tv_warrantId);
            tv_landId = (TextView) itemView.findViewById(R.id.tv_landId);
            tv_contractnumber = (TextView) itemView.findViewById(R.id.tv_contractnumber);
            tv_disputeTime = (TextView) itemView.findViewById(R.id.tv_disputeTime);
        }
    }
}
